package com.example;

import java.util.HashMap;

public class User {
    private String name;
    private int age;

    public User() {
    }

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    /* 重写父类的equals方法，自定义比较规则 */
    @Override
    public boolean equals(Object obj) {
        // 1.先判断obj的实际类型
        if (!(obj instanceof User)) {
            return false; // user对象与其他类型对象比较，肯定不相同
        }
        // 2.再判断各个属性
        User u = (User) obj;
        return name.equals(u.name) && age == u.age;
    }
}
